/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.google.common.collect.Maps;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.calendar.CalendarMailSender;
/*     */ import com.zimbra.cs.mailbox.calendar.ZAttendee;
/*     */ import com.zimbra.soap.admin.type.DomainSelector;
/*     */ import com.zimbra.soap.admin.type.DomainSelector.DomainBy;
/*     */ import java.io.PrintStream;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestCalendarMailSender
/*     */   extends TestCase
/*     */ {
/*  38 */   private static String ORGANIZERACCT = "organizerAcct";
/*  39 */   private static String ATTENDEEACCT = "attendeeAcct";
/*  40 */   private static String SYSRESOURCEACCT = "sysResourceAcct";
/*  41 */   private static String DIFFDOMAIN = "calmailsndr.example.test";
/*  42 */   private static String DIFFDOMAINACCT = "diffDomainAcct@" + DIFFDOMAIN;
/*     */   
/*     */   public void testInviteAutoDeclinePrefsUnset() throws Exception {
/*  45 */     Account organizerAccount = TestUtil.createAccount(ORGANIZERACCT);
/*  46 */     Account senderAccount = organizerAccount;
/*  47 */     Account attendeeAccount = TestUtil.createAccount(ATTENDEEACCT);
/*  48 */     Mailbox mbox = TestUtil.getMailbox(ATTENDEEACCT);
/*  49 */     String senderEmail = senderAccount.getName();
/*  50 */     ZAttendee matchingAttendee = new ZAttendee(attendeeAccount.getName(), attendeeAccount.getCn(), senderAccount.getName(), null, null, "IND", null, "NE", Boolean.valueOf(true), null, null, null, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  55 */     boolean allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/*  57 */     assertFalse(String.format("Should NOT be allowed to send auto-decline because default value for %s is false", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply" }), allowed);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void testPrefCalendarSendInviteDeniedAutoReplyTrue()
/*     */     throws Exception
/*     */   {
/*  66 */     Account organizerAccount = TestUtil.createAccount(ORGANIZERACCT);
/*  67 */     Account senderAccount = organizerAccount;
/*  68 */     Account attendeeAccount = TestUtil.createAccount(ATTENDEEACCT);
/*  69 */     Mailbox mbox = TestUtil.getMailbox(ATTENDEEACCT);
/*  70 */     String senderEmail = senderAccount.getName();
/*  71 */     Map<String, Object> prefs = Maps.newHashMap();
/*  72 */     prefs.put("zimbraPrefCalendarSendInviteDeniedAutoReply", "TRUE");
/*  73 */     Provisioning.getInstance().modifyAttrs(attendeeAccount, prefs, true, null);
/*  74 */     ZAttendee matchingAttendee = new ZAttendee(attendeeAccount.getName(), attendeeAccount.getCn(), senderAccount.getName(), null, null, "IND", null, "NE", Boolean.valueOf(true), null, null, null, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  80 */     boolean allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/*  82 */     assertTrue(String.format("Should be allowed to send auto-decline because %s=true", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply" }), allowed);
/*     */     
/*     */ 
/*  85 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, false, matchingAttendee);
/*     */     
/*  87 */     assertFalse("Should NOT be allowed to send auto-decline because appyToCalendar=false", allowed);
/*     */     
/*  89 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, null);
/*     */     
/*  91 */     assertFalse("Should NOT be allowed to send auto-decline because no matching attendee in invite", allowed);
/*     */     
/*  93 */     senderEmail = null;
/*  94 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/*  96 */     assertFalse("Should NOT be allowed to send auto-decline to null sender", allowed);
/*     */     
/*  98 */     senderEmail = "unknown@example.test";
/*  99 */     senderAccount = null;
/* 100 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 102 */     assertFalse("Should NOT be allowed to send auto-decline - no account object for sender", allowed);
/*     */     
/* 104 */     Map<String, Object> attrs = Maps.newHashMap();
/* 105 */     attrs.put("zimbraIsSystemResource", "TRUE");
/* 106 */     attrs.put("zimbraPrefCalendarSendInviteDeniedAutoReply", "TRUE");
/* 107 */     Account resourceAcct = TestUtil.createAccount(SYSRESOURCEACCT, attrs);
/* 108 */     Mailbox resMbox = TestUtil.getMailbox(SYSRESOURCEACCT);
/* 109 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(resMbox, resourceAcct, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 111 */     assertFalse("Should NOT be allowed to send auto-decline - account is a system resource", allowed);
/*     */   }
/*     */   
/*     */   public void testInternalPrefCalendarAllowedTargetsForInviteDeniedAutoReply() throws Exception {
/* 115 */     Account organizerAccount = TestUtil.createAccount(ORGANIZERACCT);
/* 116 */     Account senderAccount = organizerAccount;
/* 117 */     Account attendeeAccount = TestUtil.createAccount(ATTENDEEACCT);
/* 118 */     Mailbox mbox = TestUtil.getMailbox(ATTENDEEACCT);
/* 119 */     String senderEmail = senderAccount.getName();
/* 120 */     Map<String, Object> prefs = Maps.newHashMap();
/* 121 */     prefs.put("zimbraPrefCalendarSendInviteDeniedAutoReply", "TRUE");
/* 122 */     prefs.put("zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply", "internal");
/* 123 */     Provisioning.getInstance().modifyAttrs(attendeeAccount, prefs, true, null);
/* 124 */     ZAttendee matchingAttendee = new ZAttendee(attendeeAccount.getName(), attendeeAccount.getCn(), senderAccount.getName(), null, null, "IND", null, "NE", Boolean.valueOf(true), null, null, null, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 130 */     boolean allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 132 */     assertTrue(String.format("Should be allowed to send auto-decline because %s=true & %s=internal", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */     
/*     */ 
/* 135 */     senderAccount = null;
/* 136 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 138 */     assertFalse(String.format("Should NOT be allowed to send auto-decline for non-internal because %s=true & %s=internal", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */   }
/*     */   
/*     */ 
/*     */   public void testSameDomainPrefCalendarAllowedTargetsForInviteDeniedAutoReply()
/*     */     throws Exception
/*     */   {
/* 145 */     Account organizerAccount = TestUtil.createAccount(ORGANIZERACCT);
/* 146 */     Account senderAccount = organizerAccount;
/* 147 */     Account attendeeAccount = TestUtil.createAccount(ATTENDEEACCT);
/* 148 */     Mailbox mbox = TestUtil.getMailbox(ATTENDEEACCT);
/* 149 */     String senderEmail = senderAccount.getName();
/* 150 */     Map<String, Object> prefs = Maps.newHashMap();
/* 151 */     prefs.put("zimbraPrefCalendarSendInviteDeniedAutoReply", "TRUE");
/* 152 */     prefs.put("zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply", "sameDomain");
/* 153 */     Provisioning.getInstance().modifyAttrs(attendeeAccount, prefs, true, null);
/* 154 */     ZAttendee matchingAttendee = new ZAttendee(attendeeAccount.getName(), attendeeAccount.getCn(), senderAccount.getName(), null, null, "IND", null, "NE", Boolean.valueOf(true), null, null, null, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 160 */     boolean allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 162 */     assertTrue(String.format("Should be allowed to send auto-decline because %s=true & %s=sameDomain", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */     
/*     */ 
/* 165 */     Provisioning prov = Provisioning.getInstance();
/* 166 */     prov.createDomain(DIFFDOMAIN, new HashMap());
/* 167 */     senderAccount = prov.createAccount(DIFFDOMAINACCT, "test123", null);
/* 168 */     senderEmail = senderAccount.getName();
/* 169 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 171 */     assertFalse(String.format("Should NOT be allowed to send auto-decline to diff domain because %s=true & %s=sameDomain", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 176 */     senderAccount = null;
/* 177 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 179 */     assertFalse(String.format("Should NOT be allowed to send auto-decline to non-internal because %s=true & %s=sameDomain", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */   }
/*     */   
/*     */ 
/*     */   public void testAllPrefCalendarAllowedTargetsForInviteDeniedAutoReply()
/*     */     throws Exception
/*     */   {
/* 186 */     Account organizerAccount = TestUtil.createAccount(ORGANIZERACCT);
/* 187 */     Account senderAccount = organizerAccount;
/* 188 */     Account attendeeAccount = TestUtil.createAccount(ATTENDEEACCT);
/* 189 */     Mailbox mbox = TestUtil.getMailbox(ATTENDEEACCT);
/* 190 */     String senderEmail = senderAccount.getName();
/* 191 */     Map<String, Object> prefs = Maps.newHashMap();
/* 192 */     prefs.put("zimbraPrefCalendarSendInviteDeniedAutoReply", "TRUE");
/* 193 */     prefs.put("zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply", "all");
/* 194 */     Provisioning.getInstance().modifyAttrs(attendeeAccount, prefs, true, null);
/* 195 */     ZAttendee matchingAttendee = new ZAttendee(attendeeAccount.getName(), attendeeAccount.getCn(), senderAccount.getName(), null, null, "IND", null, "NE", Boolean.valueOf(true), null, null, null, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 201 */     boolean allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 203 */     assertTrue(String.format("Should be allowed to send auto-decline because %s=true & %s=all", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */     
/*     */ 
/* 206 */     Provisioning prov = Provisioning.getInstance();
/* 207 */     prov.createDomain(DIFFDOMAIN, new HashMap());
/* 208 */     senderAccount = prov.createAccount(DIFFDOMAINACCT, "test123", null);
/* 209 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 211 */     assertTrue(String.format("Should be allowed to send auto-decline to diff domain because %s=true & %s=all", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 216 */     senderAccount = null;
/* 217 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 219 */     assertTrue(String.format("Should be allowed to send auto-decline to non-internal because %s=true & %s=all", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 224 */     senderEmail = "fred@unknown.domain";
/* 225 */     allowed = CalendarMailSender.allowInviteAutoDeclinedNotification(mbox, attendeeAccount, senderEmail, senderAccount, true, matchingAttendee);
/*     */     
/* 227 */     assertTrue(String.format("Should be allowed to send auto-decline to external user because %s=true & %s=all", new Object[] { "zimbraPrefCalendarSendInviteDeniedAutoReply", "zimbraPrefCalendarAllowedTargetsForInviteDeniedAutoReply" }), allowed);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/* 235 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void cleanUp() throws Exception
/*     */   {
/* 240 */     TestUtil.deleteAccount(ORGANIZERACCT);
/* 241 */     TestUtil.deleteAccount(ATTENDEEACCT);
/* 242 */     TestUtil.deleteAccount(SYSRESOURCEACCT);
/* 243 */     TestUtil.deleteAccount(DIFFDOMAINACCT);
/* 244 */     Provisioning prov = Provisioning.getInstance();
/* 245 */     DomainSelector domSel = new DomainSelector(DomainSelector.DomainBy.name, DIFFDOMAIN);
/* 246 */     Domain diffDomain = prov.get(domSel);
/* 247 */     if (diffDomain != null) {
/* 248 */       prov.deleteDomain(diffDomain.getId());
/*     */     }
/*     */   }
/*     */   
/*     */   public static void main(String[] args)
/*     */     throws Exception
/*     */   {
/*     */     try
/*     */     {
/* 257 */       TestUtil.runTest(TestCalendarMailSender.class);
/*     */     } catch (Exception e) {
/* 259 */       System.out.println(e.getMessage());
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestCalendarMailSender.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */